#include "stdafx.h"
#include "Hello.h"

HRESULT STDMETHODCALLTYPE CHello::QueryInterface(REFIID riid, LPVOID* ppv){
	HRESULT hr = E_NOINTERFACE;
	*ppv = NULL;

	if(riid == IID_IUnknown || riid==IID_IHello)
		*ppv = static_cast<IHello*>(this);

	if(*ppv != NULL){
		AddRef();
		hr = S_OK;
	}
	return hr;
}

ULONG STDMETHODCALLTYPE CHello::AddRef(void){
	return ++m_cRef;
}
ULONG STDMETHODCALLTYPE CHello::Release(void){
	if(--m_cRef == 0){
		delete this;
	}
	return m_cRef;
}

CHello::CHello(void){
	m_cRef = 0;
}

CHello::~CHello(){

}

HRESULT STDMETHODCALLTYPE CHello::sayHello(wchar_t *name, wchar_t **message){
	char* buffer = (char*)::CoTaskMemAlloc(256);
	if(buffer == NULL) return E_FAIL;

	::wsprintf(buffer, "Hello %s ", name);
	*message = (wchar_t*)buffer;

	return S_OK;

}